<?php

namespace App\Http\Controllers\Common;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Common\OperationLog as logModel;

class OperationLogController extends Controller
{

    public $mark;
    protected $model;

    public function __construct()
    {
        $this->model = new logModel();
    }

    /**
     * log是否开启
     */
    public function enable()
    {
        $this->mark = config('system.action_log_enabled');
        return $this->mark;
    }

    /**
     * 获取log日志列表
     * @param Request $request
     * @return array
     */
    public function getLogList(Request $request)
    {
        try {
            $data['username'] = isset($request->username) ? trim($request->username) : '';
            $data['start_time'] = $request->has('start_time') ? $request->start_time : '';
            $data['end_time'] = $request->has('end_time') ? $request->end_time : '';

            $limit = (int) $request->input('limit');

            $sorter = $this->handleSort($request, $this->model->sorters);

            return preprocess($this->model->getLogList($limit, $sorter, $data));
        } catch (\Exception $e) {
            return $this->throwError($e);
        }
    }

}
